﻿package com.echo.ssm.aspect;

import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;


/**
 * 测试切面编程 AOP 示例 培训专用
 * @author tangsixiang
 *你好那
 */

@Component
@Aspect
public class AspectTest {
	/**
	 * 执行当前方法 aspectAddMethod  必须在 com.echo.study.spring.service.add 被执行之前
	 * @param joinPoint
	 */
/*	@Before("execution(* com.echo.ssm.service.SonService.*(..))")
	public  void  aspectAddMethodBefore(JoinPoint joinPoint){
		   System.out.print("------@Before------");
		   System.out.print("获取被执行的方法"+joinPoint.getTarget().getClass().getName());  
		   System.out.print("."+joinPoint.getSignature().getName());
		//   System.out.println("----"+joinPoint.getArgs()[0].toString());
		   Son son=(Son) joinPoint.getArgs()[0];
		     System.out.println(son);
		
	}
	
	
	*//**
	 *   连接点  
	 *   异常的 类使用 throwing
	 * @param joinPoint
	 * @param e
	 *//*
		@AfterThrowing(value="execution(* com.echo.ssm.service.SonService.*(..))" ,throwing="e")
		public  void  aspectAddMethodBefore(JoinPoint joinPoint ,Exception  e){
			    System.out.println("----异常通知-----");
				   System.out.print("."+joinPoint.getSignature().getName());
		      e.printStackTrace();
		      System.out.println("The method " + joinPoint.getSignature().getName() + " occurs exception: " + e);
		      System.out.println("----异常通知- end----");
		}
	
			*//**
			 * 前置  后置  返回通知 及异常通知的复合体
			 * @param pjd
			 * @return
			 *//*
	//@Around("execution(* com.echo.ssm.service.SonService.*(..))")
	public Object aroundMethod(ProceedingJoinPoint pjd) {
		Object result = null;
		String methodName = pjd.getSignature().getName();
		// 执行目标方法
		try {
			// 前置通知
			System.out.println("The method " + methodName + " begins with "
					+ Arrays.asList(pjd.getArgs()));
			result = pjd.proceed();
			// 返回通知
			System.out.println("The method " + methodName + " ends with "
					+ Arrays.asList(pjd.getArgs()));
		} catch (Throwable e) {
			// 异常通知
			System.out.println("The method " + methodName
					+ " occurs expection : " + e);
			throw new RuntimeException(e);
		}
		// 后置通知
		System.out.println("The method " + methodName + " ends");
		return result;
	}
*/
	 
}
